package com.nd.android.musicboxlibrary.util.fastDateUtil;

import java.util.Calendar;

/**
 * <p>
 * Inner class to output one of a set of values.
 * </p>
 */
public class TextField implements Rule {
    private final int mField;

    private final String[] mValues;

    /**
     * Constructs an instance of <code>TextField</code> with the specified field and values.
     * 
     * @param field
     *            the field
     * @param values
     *            the field values
     */
    public TextField(int field, String[] values) {
        mField = field;
        mValues = values;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int estimateLength() {
        int max = 0;
        for (int i = mValues.length; --i >= 0;) {
            int len = mValues[i].length();
            if (len > max) {
                max = len;
            }
        }
        return max;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void appendTo(StringBuffer buffer, Calendar calendar) {
        buffer.append(mValues[calendar.get(mField)]);
    }
}
